package com.glodon.paas.account.dao.mongo;

import net.oauth.OAuthConsumer;

import com.glodon.paas.account.dao.OAuthConsumerDao;
import com.glodon.paas.account.dao.domain.ConsumerEntity;
import com.google.code.morphia.query.Query;

public class OAuthConsumerDaoMongoImpl extends MongoDBDao<ConsumerEntity, String> implements OAuthConsumerDao {

	@Override
	public OAuthConsumer readConsumer(String consumer_key) {
		Query<ConsumerEntity> q = this.createQuery().filter("consumerkey =", consumer_key);
		ConsumerEntity c = q.get();
		if(c!=null){
			 OAuthConsumer consumer = new OAuthConsumer(c.getCallbackURL(), c.getConsumerkey(), c.getConsumerSecrect(), null);
             consumer.setProperty("name", c.getConsumerkey());
             consumer.setProperty("description", c.getDescription());
			return consumer;
		}
		else{
			return null;
		}
	}
}
